﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KBVault.Web.Infrastructure;
using KBVault.DAL.Repository;

namespace KBVault.Web.Application
{
    public partial class Profile : KBVaultAdminPage
    {
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            var currentUser = SessionManager.GetCurrentUser();
            if (!UserRepository.Validate(currentUser.UserName, txtOldPassword.Text))
            {
                ShowError("Wrong Password. Please enter correct old password.");
                return;
            }
            if( !txtNewPassword.Text.Equals(txtNewPasswordControl.Text) )
            {
                ShowError("New passwords do not match.");
                return;
            }
            currentUser.Password = txtNewPassword.Text;
            UserRepository.Update(currentUser, true);
            ShowMessage("Profile updated successfully :)");

        }
    }
}